package LeetCode.month03.day73;
import java.util.*;

/**
 * @author 16778
 * @date 2025/10/13 8:18
 * @description
 */
public class No2273 {
    public List<String> removeAllAnagrams(String[] words) {
        List<String> res = new ArrayList<>();
        int n = words.length;
        Map<String,Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int[] ints = new int[26];
            String s = words[i];
            for (int j = 0; j < s.length(); j++) {
                int index = s.charAt(j)-'a';
                ints[s.charAt(j)-'a']++;
            }
            String s1 = Arrays.toString(ints);
            if(!map.containsKey(s1)){
                map.put(s1,i);
                res.add(s);
            }
        }
        return res;
    }

    public List<String> removeAnagrams(String[] words) {
        int n = words.length;
        List<String> res = new ArrayList<>();
        List<String> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int[] ints = new int[26];
            String s = words[i];
            for (int j = 0; j < s.length(); j++) {
                int index = s.charAt(j)-'a';
                ints[s.charAt(j)-'a']++;
            }
            String s1 = Arrays.toString(ints);
            if(i==0){
                res.add(s);
            }
            if(i>0) {
                if (!list.get(i - 1).equals(s1)){
                    res.add(s);
                }
            }
            list.add(s1);
        }
        return res;
    }
}
